<template>
  <div>
    <el-select v-model="channelId" placeholder="请选择" @change="change">
      <el-option
        v-for="item in channelOptions"
        :key="item.id"
        :label="item.name"
        :value="item.id"
        >
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { getChannelsListAPI } from '../../../api/index.js'
export default {
  name: 'MyChannel',
  props: {
    channel_id: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      channelId: null,
      channelOptions: []
    }
  },
  created () {
    this.getchannelOptions()
  },
  watch: {
    channel_id: {
      immediate: true,
      handler (newValue, oldValue) {
        this.channelId = newValue
        console.log('111111' + oldValue)
        console.log('222222' + newValue)
      }
    }
  },
  methods: {
    // 获取频道列表
    async getchannelOptions () {
      try {
        const { data: res } = await getChannelsListAPI()
        this.channelOptions = res.data.channels
        console.log(res)
      } catch (error) {
        console.log(error)
      }
    },
    change () {
      this.$emit('channelChange', this.channelId)
    }
  }
}
</script>

<style>

</style>
